<template>
  <div>
    <TopFilter :list="topFilterList" :cols="4" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      height="200"
      columnsRef="jzyBrand"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="searchDetail"
    >
    </FilterTable>
    <TopFilter :list="inputDate1" :cols="4" @filterChange="changeHandle1" @onCollapse="collapseHandle1"></TopFilter>
    <FilterTable
      ref="table"
      height="200"
      columnsRef="mxjBrand"
      :columns="columns1"
      :fetchapi="fetchApiDetail"
      :params="fetchParams1"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns1 = columns)"
    >
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <BrandModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { searchPartWaterByDto } from '@/api/parts/partResource/partWater';
import { searchPartWaterDetail } from '@/api/parts/partResource/partWater';
import BrandModal from './tabs/brandModal';
import { join } from 'path';

export default {
  name: 'Brand',
  components: {
    BrandModal
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑', show: '显示' };
    return {
      js: {
        partNo: '',
        storageCodeName: ''
      },
      topFilterList: this.createTopFilterList(),
      inputDate1: this.inputDate(),
      fetchParams: {},
      fetchParams1: {},
      visible: false,
      dialogTitle: '',
      fetchApi: searchPartWaterByDto,
      fetchApiDetail: searchPartWaterDetail,
      columns: this.createTableColumns(),
      columns1: this.createTableColumns1(),
      handleType: '',
      formData: {}
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    inputDate() {
      return [
        {
          type: 'RANGE_DATE',
          label: '查看日期',
          fieldName: 'start|end',
          placeholder: '查看日期',
          width: 400
        }
      ];
    },
    createTopFilterList() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'storageCode',
          placeholder: '仓库...',
          itemList: [
            { value: 10451001, text: '店面' },
            { value: 10451003, text: '厂家' }
          ]
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partNo',
          placeholder: '配件代码'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName',
          placeholder: '配件名称'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商简称',
          dataIndex: 'dealerShortname',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '仓库',
          dataIndex: 'storageCodeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库位',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '计量单位',
          dataIndex: 'UNIT_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借进数量',
          dataIndex: 'BORROW_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借出数量',
          dataIndex: 'LEND_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '可用库存',
          dataIndex: 'USEABLE_STOCK',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '最新入库日期',
          dataIndex: 'LAST_STOCK_IN',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '最新出库日期',
          dataIndex: 'LAST_STOCK_OUT',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    createTableColumns1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '发生日期',
          dataIndex: 'OPERATE_DATE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '进出类型',
          dataIndex: 'IN_OUT_TYPE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '进数量',
          dataIndex: 'STOCK_IN_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出数量',
          dataIndex: 'STOCK_OUT_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出入库不含税单价',
          dataIndex: 'IN_OUT_NET_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出入库不含税金额',
          dataIndex: 'IN_OUT_NET_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出入库含税单价',
          dataIndex: 'IN_OUT_TAXED_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出入库含税金额',
          dataIndex: 'IN_OUT_TAXED_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '成本单价',
          dataIndex: 'COST_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单据号码',
          dataIndex: 'SHEET_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '操作员',
          dataIndex: 'OPERATOR_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },

    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    searchDetail(row) {
      console.log(row);
      if (row.length > 0) {
        this.js = row[0];
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    collapseHandle1() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    changeHandle1(val) {
      console.log(val);
      console.log(this.js);
      let data = {
        start: val.start,
        end: val.end,
        partNo: this.js.partNo,
        storageCodeName: this.js.storageCodeName
      };
      this.fetchParams1 = Object.assign({}, data);
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}品牌`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
